package com.sangeng.controller;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@SessionAttributes(value = {"name"})
public class JspController {


    @RequestMapping("/testRquestScope")
    public String testRquestScope(Model model) {
        model.addAttribute("name", "杨琛");
        model.addAttribute("title", "我爱你");
        return "testScope";
    }


    @RequestMapping("/testRquestScope2")
    public ModelAndView testRquestScope2(ModelAndView modelAndView) {
        modelAndView.addObject("name","三更");
        modelAndView.addObject("title","java教学");
        //页面跳转
        modelAndView.setViewName("testScope");
        return modelAndView;
    }


    @RequestMapping("/testGetAttribute")
    //输入域对象中的key可获取到
    public String testGetAttribute(@RequestAttribute("***") String value) {
        return "testScope";
    }



    @RequestMapping("/testSessionScope")
    public String testSessionScope(Model model) {
        model.addAttribute("name", "杨琛");
        model.addAttribute("title", "我爱你");
        return "testScope";
    }

    @RequestMapping("/testSessionAttr")
    //获取session域对象
    public String testSessionAttr(@SessionAttribute("name") String name,HttpSession httpSession) {
        System.out.println();
        return "testScope";
    }
}
